package com.zthz.douxing.event

import com.zthz.douxing.msg.MessageType
import com.zthz.douxing.sendmessageservice.handlers.AbstractMessageHandlerService
import com.zthz.douxing.sendmessageservice.thirdmessagesender.BaseMessageSenderService
import com.zthz.douxing.sendmessageservice.utils.OrderXingeMessageService
import org.quartz.Job
import org.quartz.JobDataMap
import org.quartz.JobExecutionContext
import org.quartz.JobExecutionException

/**
 * Created by zsw on 5/11/14.
 */
class UserWillTripWeatherJob implements Job {

    @Override
    void execute(JobExecutionContext context) throws JobExecutionException {
        JobDataMap jobDataMap = context.getMergedJobDataMap()

        BaseMessageSenderService baseMessageSenderService = jobDataMap.get("baseMessageSenderService")
        OrderXingeMessageService orderXingeMessageService = jobDataMap.get("orderXingeMessageService")
        UserWillDepartEvent userWillTripEvent = jobDataMap.get("userWillTripEvent")
        String msgContent = jobDataMap.get("msgContent")
        try{
            Map param = baseMessageSenderService.getParamFromUserWillDepartEvent4PlanForm(userWillTripEvent,msgContent,MessageType.WeatherInfo)
            String resultDesc = baseMessageSenderService.send2One(param)
            orderXingeMessageService.saveMessageToUserLog(userWillTripEvent,msgContent,resultDesc,MessageType.WeatherInfo)

        }catch (Exception e){
            throw e
        }finally{
            context.getScheduler().deleteJob(context.getJobDetail().getKey())
        }

    }

}
